package org.example.controller;

import org.example.domain.User;
import org.springframework.web.bind.annotation.*;

//@Controller @ResponseBody  合二为一  @RestController
@RestController
@RequestMapping("/books")
public class BookController {

//    @RequestMapping(method = RequestMethod.POST)
    @PostMapping
    public String save() {
        System.out.println("BookController-save..");
        return "{'BookController':'save'}";
    }

//    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    @DeleteMapping("/{id}")
    public String delete(@PathVariable Integer id) {
        System.out.println("BookController-delete..id=" + id);
        return "{'BookController':'delete-id=" + id + "'}";
    }

//    @RequestMapping(method = RequestMethod.PUT)
    @PutMapping
    public String update(@RequestBody User user) {
        System.out.println("BookController-update.." + user);
        return user.toString();
    }

//    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @GetMapping("/{id}")
    public String getById(@PathVariable Integer id) {
        System.out.println("BookController-getById..id=" + id);
        return "{'BookController':'getById-id=" + id + "'}";
    }

//    @RequestMapping(method = RequestMethod.GET)
    @GetMapping
    public String getAll() {
        System.out.println("BookController-getAll..");
        return "{'BookController':'getAll'}";
    }
}
